<?php
namespace app\modules\member\models;

use Yii;
use app\models\Basic;

class MemberMessage extends Basic
{
    
    public static function tableName()
    {
        return '{{%member_message}}';
    }

    public function rules()
    {
        return [
            ['appid', 'required', 'message' => 'appid不能为空'],
            ['appid', 'string', 'message' => 'appid必须是字符串',
                      'min' => 18, 'tooShort' => 'appid最短18位',
                      'max' => 18, 'tooLong' => 'appid最长18位'],
            ['member_id', 'required', 'message' => 'member_id不能为空'],
            // ['member_id', 'default', 'value' => 0],
            ['member_id', 'integer', 'message' => 'member_id必须为数字，或数字字符串', 
                        'min'=>0, 'tooSmall' => 'member_id最小存储0', 
                        'max'=>4294967295, 'tooBig' => 'member_id最大存储4294967295'],
            ['title', 'required', 'message' => 'title不能为空'],
            ['title', 'string', 'message' => 'title必须是字符串', 
                                'max' => 128, 'tooLong' => 'title最长128位'],
            ['content', 'required', 'message' => 'content不能为空'],
            ['content', 'string', 'message' => 'content必须是字符串'],
            ['issys', 'in', 'range' => ['1', '2'],  'message' => 'issys格式不正确'],
            ['isread', 'in', 'range' => ['1', '2'],  'message' => 'isread格式不正确'],
            ['isdel', 'in', 'range' => ['1', '2'],  'message' => 'isdel格式不正确'],
            ['add_time', 'default', 'value' => '1000-01-01 00:00:00'],
            ['add_time', 'date', 'format'=>'yyyy-MM-dd HH:mm:ss', 'message' => 'add_time非yyyy-MM-dd HH:mm:ss格式'],
        ];
    }


    /*添加信息*/
    public function addMes($data)
    {
        $data['MemberMessage']['add_time'] = date('Y-m-d H:i:s', time());
        if($this->load($data) and $this->validate()){
            if($this->save(false)){
                // $id = $this->getPrimaryKey();
                return true;
            }
        }
        return false;
    }

    
}